package com.chendx.store.page.mq.listenner;

import com.alibaba.fastjson.JSON;
import com.chendx.model.goods.pojo.Sku;
import com.chendx.model.search.dto.SearchDto;
import com.chendx.store.page.service.PageService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * Created by chendx on 2022/5/12.
 */
@RabbitListener(queues = "page_sku_update_queue")
@Component
public class SkuUpdateListenner {

    @Autowired
    private PageService pageService;

    @RabbitHandler
    public void receiver(String message){
        if (!StringUtils.isEmpty(message)){
            Sku sku = null;
            try {
                sku = JSON.parseObject(message, Sku.class);
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
            if (sku == null){
                return;
            }
            SearchDto dto = new SearchDto();
            if (StringUtils.isEmpty(sku.getPrice())){
                return;
            }
            pageService.createSkuPageHtml(sku.getSpuId(),sku.getId());
        }
    }
}
